package cn.biwysh.exam.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.biwysh.exam.biz.ExamBiz;
import cn.biwysh.exam.biz.ZhiShiBiz;
import cn.biwysh.exam.entity.Exam;
import cn.biwysh.exam.entity.User;

public class Mykh extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
		response.setContentType("text/html");
		request.setCharacterEncoding("UTF-8");
		String url="WEB-INF/jsp/mykh.jsp";
		HttpSession session = request.getSession(false);
		User user=null;
		if(session!=null){
			if (session.getAttribute("userqt") != null) {
				user = (User) session.getAttribute("userqt");
				if(user!=null){
					ExamBiz biz=new ExamBiz();
					Date now=new Date();
					String nowstr=(now.getYear()+1900)+"-"+(now.getMonth()+1)+"-"+now.getDate();
					List<Exam> list=biz.GetExamByPage(" and endtime>'"+nowstr+"' and starttime<'"+nowstr+" 00:00:01'", 1, 100000);
					for (Exam exam : list) {
						exam.setIsexamed(biz.CheckExits(user.getId(), exam.getId()));
					}
					request.setAttribute("nowlist", list);
					request.setAttribute("oldlist", biz.GetExamByUser(user.getId()));
					RequestDispatcher requestDispatcher = request.getRequestDispatcher(url);
					requestDispatcher.forward(request, response);
				}else{
					response.sendRedirect("index.do");
				}
			}else{
				response.sendRedirect("index.do");
			}
		}else{
			response.sendRedirect("index.do");
		}
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
     this.doGet(request, response);
	}


}
